//
//  CNBBSFavoriteViewModel.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2018/6/1.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "CNBBSFavoriteViewModel.h"
#import <CNBaseViewTool/CSDNUser.h>
@implementation CNBBSFavoriteViewModel

/**
 编辑论坛版块是否感兴趣
 
 @param forumId 类型
 @param isFavorite 是否感兴趣
 */
-(void)getBBSFavoriteWithForumId:(NSString *)forumId AndIsFavorite:(BOOL)isFavorite CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSFavoriteWithForumId:forumId AndIsFavorite:isFavorite completionHandle:^(CNBBSFavoriteModel *model, NSError *error) {
    
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
                self.success = model.data;
            }
            else if (self.code == 401)
            {
                //未登录
                [[CSDNUser currentUser] reset];
            }
            
        }
        completionHandle(error);
    }];
}


/**
 发帖
 
 @param title 标题
 @param body  内容
 @param forumId 类型
 @param point 积分
 @return 网络请求任务
 */
-(void)getBBSPostedWithTitle:(NSString *)title AndBody:(NSString *)body AndForumId:(NSString *)forumId AndPoint:(NSString *)point CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSPostedWithTitle:title AndBody:body AndForumId:forumId AndPoint:point completionHandle:^(CNBBSPostedModel *model, NSError *error) {
        
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
               
            }
            else if (self.code == 401)
            {
                //未登录
                [[CSDNUser currentUser] reset];
            }
            
        }
        completionHandle(error);
    }];
}

/**
 获取BBS积分
 
 */
-(void)getBBSScoreCompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSScoreCompletionHandle:^(CNBBSPostedImageModel *model, NSError *error) {
        
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
                self.score = model.data;
            }
            
        }
        completionHandle(error);
    }];
}

/**
 上传图片
 
 @param imageArray 图片数组
 @param fileNames  图片名
 @param imageType  图片类型
 @return 网络请求任务
 */
-(void)getBBSUpLoadPicWithImageArray:(NSArray *)imageArray AndImageTypes:(NSArray *)imageTypes CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSUpLoadPicWithImageArray:imageArray AndImageTypes:imageTypes completionHandle:^(CNBBSPostedImageModel *model, NSError *error) {
    
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
                self.url = model.data;
            }
            
        }
        completionHandle(error);
    }];
}
@end
